package com.wenwei.paper.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.paper.R;
import com.wenwei.paper.base.BaseActivity;
import com.wenwei.paper.base.Constant;
import com.wenwei.paper.bean.ReplenishmentDetailBean;
import com.wenwei.paper.net.ApiManager;
import com.wenwei.paper.net.BaseSubscriber;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13.
 */
public class ReplenishmentDetailsActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.replenishment_number)
    TextView replenishmentNumber;
    @Bind(R.id.replenishment_time)
    TextView replenishmentTime;
    @Bind(R.id.replenishment_image)
    ImageView replenishmentImage;
    @Bind(R.id.replenishment_name)
    TextView replenishmentName;
    @Bind(R.id.replenishment_goods_num)
    TextView replenishmentGoodsNum;
    @Bind(R.id.replenishment_address)
    TextView replenishmentAddress;

    private int detailsId;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_replenishment_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void init() {
        super.init();
        detailsId = getIntent().getIntExtra("id", 0);
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("补货详情");
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void initData() {
        super.initData();
        getDetails();
    }

    private BaseSubscriber<ReplenishmentDetailBean> detailsSubscriber;

    private void getDetails() {
        detailsSubscriber = new BaseSubscriber<ReplenishmentDetailBean>(mContext) {
            @Override
            public void onSuccess(ReplenishmentDetailBean replenishmentDetailBean) {
                replenishmentNumber.setText("柜号："+replenishmentDetailBean.getNum());
                replenishmentTime.setText(replenishmentDetailBean.getTime());
                replenishmentName.setText(replenishmentDetailBean.getGoods_name());
                replenishmentGoodsNum.setText("补货数量x"+replenishmentDetailBean.getSto());
                replenishmentAddress.setText(replenishmentDetailBean.getAddress());
                Glide.with(mContext).load(Constant.BASE_IMG_URL+replenishmentDetailBean.getGoods_img()).into(replenishmentImage);
            }
        };
        ApiManager.getInstance().getReplenishmentDetails(detailsSubscriber, detailsId);
    }
}
